<template>
  <div class="base-progress-container">
    <!-- <div class="top-box">{{ day }}</div> -->
    <div class="base-progress-content">
      <el-tooltip
        v-for="(item, index) in dateList"
        :key="index"
        class="item"
        effect="dark"
        :content="item.name"
        placement="top"
        :disabled="!item.name"
      >
        <div
          :class="
            `item-box ${
              item.type
                ? item.name == '春节'
                  ? 'new-year-color'
                  : 'holiday-color'
                : ''
            } ${
              getCurrentColor(item.day, day)
                ? item.type
                  ? item.name == '春节'
                    ? 'new-year-color-active'
                    : 'holiday-color-active'
                  : 'active-color'
                : ''
            }`
          "
          @click="setCurrentDate(item)"
        >
          <div
            v-if="item.day == day"
            class="top-box"
            :style="`right:${index >= dateList.length - 21 ? '-5px' : 'auto'}`"
          >
            {{ day }}
          </div>
        </div>
      </el-tooltip>
    </div>
    <div class="bottom-time-content" v-if="dateList && dateList.length">
      <div class="bottom-time-box" v-if="dateList && dateList.length">
        <div>{{ dateList[0].day }}</div>
        <div>{{ dateList[dateList.length - 1].day }}</div>
      </div>
    </div>
  </div>
</template>
<script>
import { createNamespacedHelpers } from 'vuex'
const { mapState: mapStateForm } = createNamespacedHelpers('gisForm')
export default {
  props: ['dateList'],
  data() {
    return {
      dateList: []
    }
  },
  methods: {
    setCurrentDate(item) {
      this.$emit('percentChange', item.day)
    }
  },
  computed: {
    getCurrentColor() {
      return function(day, currentValue) {
        const dayList = this.dateList.map(item => item.day)
        let index = dayList.indexOf(currentValue)
        index = index != -1 ? index + 1 : index
        const newList = dayList.splice(0, index)
        return newList.indexOf(day) != -1
      }
    },
    ...mapStateForm(['day']),
    progressColor() {
      return function(name) {
        switch (item) {
          case '元旦':
            return 'holiday-color-active'
            break
          case '春节':
            return 'new-yea-color-active'
            break
          case '元宵节':
            return 'holiday-color-active'
            break
          default:
            return 'active-color'
            break
        }
      }
    }
  },
  watch: {
    dateList: {
      immediate: true,
      deep: true,
      handler(newVal) {
        this.dateList = newVal
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.base-progress-container {
  width: 220px;
  position: relative;
  .top-box {
    font-size: 12px;
    position: absolute;
    top: -18px;
  }

  .base-progress-content {
    display: flex;
    align-items: center;
    background-color: #dde3ee;
    width: 100%;
    height: 10px;
    border-radius: 6px;
    cursor: pointer;
    .item-box:first-child {
      border-top-left-radius: 6px;
      border-bottom-left-radius: 6px;
    }
    .item-box:last-child {
      border-top-right-radius: 6px;
      border-bottom-right-radius: 6px;
    }
    .item-box {
      display: flex;
      flex: 1;
      height: 100%;
    }
    .holiday-color {
      background-color: #f9dede;
    }
    .holiday-color-active {
      background-color: #fc5353;
    }
    .new-year-color-active {
      background-color: #fd9e52 !important;
    }
    .new-year-color {
      background-color: #fceedf;
    }
    .active-color {
      background-color: #4b71b0;
    }
  }
  .bottom-time-content {
    position: absolute;
    width: 100%;
    .bottom-time-box {
      display: flex;
      justify-content: space-between;
      font-size: 12px;
    }
  }
}
</style>
